/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 2 -*- */
/**
* @headerfile softservo.hpp
* 
* Header for easy managing the power of a servo or PWM controlled engine.
* 
* @author Miguel Ángel Vílchez López 2010 <sacra@openmatica.es>
*
* Codigo is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* Codigo is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _MOKARDU_SOFTSERVO_HPP_
#define _MOKARDU_SOFTSERVO_HPP_

/**
* @class CMSoftServo
* @brief Managing a servo or PWM controlled engine.
*/

class CMSoftServo
{

	private:
		
		/**
		* The minimum value( maximum negative ).
		*/
		int min;

		/**
		* The maximum value( maximum positive ).
		*/
		int max;
		
		/**
		* The acceleration.
		*/
		int acceleration;

		/**
		* Motor current value.
		*/
		int now;

		/**
		* Motor desired value.
		*/
		int end;


	public:
	
		/**
		* Constructor.
		*
		* @param[in] acceleration The acceleration.
		* @param[in] min The minimum power.
		* @param[in] max The maximum power.
		*/
		CMSoftServo(int acceleration,int min,int max);
		
		/**
		* Destructor.
		*/
		~CMSoftServo();
		
		/**
		* Change motor desired value.
		*
		* @param[in] value The value of desired power.
		*/
		void setEnd(int value);

		/**
		* Get the current value of motor.
		*
		* @return The current motor value.
		*/
		int getNow();

		/**
		* Motor emergency stop.
		*/
		void stop();
		
		/**
		* Accelerate the motor from now to end.
		*
		* @return Returns 0 if succesfull, -1 if not.
		*/
		int update();

};
		
#endif // _MOKARDU_SOFTSERVO_HPP_
